﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace WMS.FC.Infrastructure.Common
{
    public static class POConfigHelper
    {
        public static PropertyBuilder<bool> ConfigColumn(this PropertyBuilder<bool> builder, string columnName, string comment)
        {
            return builder.HasColumnName(columnName).HasColumnType("NUMBER(1)").HasComment(comment).IsRequired();
        }

        public static PropertyBuilder<bool?> ConfigColumn(this PropertyBuilder<bool?> builder, string columnName, string comment)
        {
            return builder.HasColumnName(columnName).HasColumnType("NUMBER(1)").HasComment(comment);
        }

        public static PropertyBuilder<byte> ConfigColumn(this PropertyBuilder<byte> builder, string columnName, string comment)
        {
            return builder.HasColumnName(columnName).HasColumnType("NUMBER(3)").HasComment(comment).IsRequired();
        }

        public static PropertyBuilder<byte?> ConfigColumn(this PropertyBuilder<byte?> builder, string columnName, string comment)
        {
            return builder.HasColumnName(columnName).HasColumnType("NUMBER(3)").HasComment(comment);
        }

        public static PropertyBuilder<short> ConfigColumn(this PropertyBuilder<short> builder, string columnName, string comment)
        {
            return builder.HasColumnName(columnName).HasColumnType("NUMBER(5)").HasComment(comment).IsRequired();
        }

        public static PropertyBuilder<short?> ConfigColumn(this PropertyBuilder<short?> builder, string columnName, string comment)
        {
            return builder.HasColumnName(columnName).HasColumnType("NUMBER(5)").HasComment(comment);
        }

        public static PropertyBuilder<int> ConfigColumn(this PropertyBuilder<int> builder, string columnName, string comment)
        {
            return builder.HasColumnName(columnName).HasColumnType("NUMBER(10)").HasComment(comment).IsRequired();
        }

        public static PropertyBuilder<int?> ConfigColumn(this PropertyBuilder<int?> builder, string columnName, string comment)
        {
            return builder.HasColumnName(columnName).HasColumnType("NUMBER(10)").HasComment(comment);
        }

        public static PropertyBuilder<long> ConfigColumn(this PropertyBuilder<long> builder, string columnName, string comment)
        {
            return builder.HasColumnName(columnName).HasColumnType("NUMBER(19)").HasComment(comment).IsRequired();
        }

        public static PropertyBuilder<long?> ConfigColumn(this PropertyBuilder<long?> builder, string columnName, string comment)
        {
            return builder.HasColumnName(columnName).HasColumnType("NUMBER(19)").HasComment(comment);
        }

        public static PropertyBuilder<decimal> ConfigColumn(this PropertyBuilder<decimal> builder, string columnName, string comment)
        {
            return builder.HasColumnName(columnName).HasColumnType("NUMBER(18,2)").HasComment(comment).IsRequired();
        }

        public static PropertyBuilder<decimal?> ConfigColumn(this PropertyBuilder<decimal?> builder, string columnName, string comment)
        {
            return builder.HasColumnName(columnName).HasColumnType("NUMBER(18,2)").HasComment(comment);
        }

        public static PropertyBuilder<string> ConfigColumn(this PropertyBuilder<string> builder, string columnName, string comment, int length, bool isRequired = true)
        {
            if (length < 4000)
                return builder.HasColumnName(columnName).HasColumnType($"VARCHAR2({length})").IsUnicode(false).IsFixedLength(false).HasMaxLength(length).HasComment(comment).IsRequired();
            else
                return builder.HasColumnName(columnName).HasColumnType("CLOB").IsUnicode(false).IsFixedLength(false).HasMaxLength(length).HasComment(comment).IsRequired();
        }

        public static PropertyBuilder<string?> ConfigColumn(this PropertyBuilder<string?> builder, string columnName, string comment, int length)
        {
            if (length < 4000)
                return builder.HasColumnName(columnName).HasColumnType($"VARCHAR2({length})").IsUnicode(false).IsFixedLength(false).HasMaxLength(length).HasComment(comment);
            else
                return builder.HasColumnName(columnName).HasColumnType("CLOB").IsUnicode(false).IsFixedLength(false).HasMaxLength(length).HasComment(comment);
        }

        public static PropertyBuilder<DateTime> ConfigColumn(this PropertyBuilder<DateTime> builder, string columnName, string comment)
        {
            return builder.HasColumnName(columnName).HasColumnType("TIMESTAMP(7)").HasComment(comment).IsRequired();
        }

        public static PropertyBuilder<DateTime?> ConfigColumn(this PropertyBuilder<DateTime?> builder, string columnName, string comment)
        {
            return builder.HasColumnName(columnName).HasColumnType("TIMESTAMP(7)").HasComment(comment);
        }

        public static PropertyBuilder<byte[]> ConfigColumn(this PropertyBuilder<byte[]> builder, string columnName, string comment)
        {
            return builder.HasColumnName(columnName).HasColumnType("RAW(2000)").HasComment(comment).IsRequired();
        }
    }
}
